package tests;

import java.util.Scanner;

public class test5 {
    int num;
    public static int isFun(int num){
        int geshu=0;
        while(num>1){
            geshu+=num/3;
            num=num/3+num%3;
            if(num==2){
                ++geshu;
                break;
            }
        }
        return geshu;
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int num;
        while((num= sc.nextInt())!=0){
            System.out.println(isFun(num));
        }
    }
}
